package com.wst.Controller;

import com.wst.cxf.CxfClient;
import com.wst.http.HttpAPIService;
import com.wst.http.HttpResult;
import com.wst.mapper.TestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

@Controller
@RequestMapping("/MyController")
public class MyController {

    @Autowired
    @Qualifier("httpAPIService")
    private HttpAPIService httpAPIService;
    @Autowired
    private TestMapper testMapper;
    private static int flag = 0;
    @Autowired
    private RestTemplate restTemplate;
    /**
     *  测试httpClient
     */
    @RequestMapping("/httpclient")
    @ResponseBody
    public String test() throws Exception {
        System.out.println("5秒运行一次！！！，运行第" + flag++ + "次");
        HttpResult httpResult = httpAPIService.doPost("http://localhost:9002/test/interface");
        System.out.println("http返回状态码：" + httpResult.getCode());
        return "httpclient测试：success";
    }
    /**
     * 测试cxf调用webservice接口
     */
    @RequestMapping("/cxf")
    @ResponseBody
    public String test1() {
        String[] params = {"这是我的测试webservice用例"};
        Object[] sendMessages = CxfClient.invokeRemoteMethod("http://localhost:8080/services/TestService1", "sendMessage", params);
        System.out.println(sendMessages[0]);
        return "cxf测试：success";
    }
    /**
     * restTemplate测试restful接口
     */
    @RequestMapping("/restful")
    @ResponseBody
    public String test3(String name) {
        String forObject = restTemplate.getForObject("http://localhost:9002/test/restful/"+name, String.class);
        return forObject;
    }
}
